package com.qianfeng.myymatou.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qianfeng.myymatou.R;
import com.qianfeng.myymatou.bean.ForeignGoodsBean;
import com.qianfeng.myymatou.view.ForeignGoodsView;

import java.util.List;

/**
 * Created by Administrator on 2016/7/19.
 * <p/>
 * “特卖”页面中“洋货团”的RecyclerView的适配器
 */
public class ForeignGoodsRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<ForeignGoodsBean.DataBean.PagePartsBean> mPagePartsBeenList;

    public ForeignGoodsRvAdapter(Context context, List<ForeignGoodsBean.DataBean.PagePartsBean> pagePartsBeenList) {
        this.mContext = context;
        this.mPagePartsBeenList = pagePartsBeenList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_rv_foreign_goods, parent, false);
        return new ForeignGoodsHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ForeignGoodsBean.DataBean.PagePartsBean pagePartsBean = mPagePartsBeenList.get(position);
        ((ForeignGoodsHolder) holder).fgvItem.setProductsList(pagePartsBean.getBannerUrl(), pagePartsBean.getProducts(), pagePartsBean.getTotal());
    }

    @Override
    public int getItemCount() {
        return mPagePartsBeenList == null ? 0 : mPagePartsBeenList.size();
    }

    class ForeignGoodsHolder extends RecyclerView.ViewHolder {
        private ForeignGoodsView fgvItem;

        public ForeignGoodsHolder(View itemView) {
            super(itemView);
            fgvItem = (ForeignGoodsView) itemView.findViewById(R.id.fgv_item);
        }
    }

    public void updateData() {
        notifyDataSetChanged();
    }
}
